bitkeeper revision 1.1159.30.1 (411ddb8cj12XLuMNx_qS9SGeej51OQ)
authorgm281@boulderdash.cl.cam.ac.uk <gm281@boulderdash.cl.cam.ac.uk>
Sat, 14 Aug 2004 09:29:48 +0000 (09:29 +0000)
committergm281@boulderdash.cl.cam.ac.uk <gm281@boulderdash.cl.cam.ac.uk>
Sat, 14 Aug 2004 09:29:48 +0000 (09:29 +0000)
cpu_weight parameter added to the xm create command. Minor bug fix for BVT.

tools/libxc/xc.h
tools/libxc/xc_domain.c
tools/libxc/xc_linux_restore.c
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py
xen/common/sched_bvt.c

index b2cf0c67ba4826a38d11843f777b1f164c16000e..046a00c2689aa0ba37a5ed50b82e04691587cfc4 100644 (file)
@@ -48,6 +48,7 @@ int xc_domain_create(int xc_handle,
                      unsigned int mem_kb, 
                      const char *name,
                      int cpu,
+                     float cpu_weight,
                      u32 *pdomid);
 int xc_domain_pause(int xc_handle, 
                     u32 domid);
@@ -62,6 +63,9 @@ int xc_domain_getinfo(int xc_handle,
                       u32 first_domid, 
                       unsigned int max_doms,
                       xc_dominfo_t *info);
+int xc_domain_setcpuweight(int xc_handle,
+                           u32 domid,
+                           float weight);
 
 int xc_shadow_control(int xc_handle,
                       u32 domid, 
@@ -209,6 +213,9 @@ typedef struct {
 int xc_physinfo(int xc_handle,
                 xc_physinfo_t *info);
 
+int xc_sched_id(int xc_handle,
+                int *sched_id);
+
 int xc_domain_setname(int xc_handle,
                       u32 domid, 
                       char *name);
index 10017c74fe7cb6a415e0dcab62d6050510b1a1cf..6fab304f2efa03a824917856fe91f19722eefbd0 100644 (file)
@@ -12,6 +12,7 @@ int xc_domain_create(int xc_handle,
                      unsigned int mem_kb, 
                      const char *name,
                      int cpu,
+                     float cpu_weight,
                      u32 *pdomid)
 {
     int err;
@@ -25,7 +26,11 @@ int xc_domain_create(int xc_handle,
     op.u.createdomain.cpu = cpu;
 
     if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
+    {
         *pdomid = (u16)op.u.createdomain.domain;
+        
+         err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight);
+    }
 
     return err;
 }    
@@ -171,6 +176,64 @@ int xc_domain_setname(int xc_handle,
     return do_dom0_op(xc_handle, &op);
 }
 
+int xc_domain_setcpuweight(int xc_handle,
+                           u32 domid,
+                           float weight)
+{
+    int sched_id;
+    int ret;
+    
+    /* Figure out which scheduler is currently used: */
+    if((ret = xc_sched_id(xc_handle, &sched_id)))
+        return ret;
+    
+    switch(sched_id)
+    {
+        case SCHED_BVT:
+        {
+            u32 mcuadv;
+            int warpback;
+            s32 warpvalue;
+            long long warpl;
+            long long warpu;
+
+            /* Preserve all the scheduling parameters apart 
+               of MCU advance. */
+            if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv, 
+                                &warpback, &warpvalue, &warpl, &warpu)))
+                return ret;
+            
+            /* The MCU advance is inverse of the weight.
+               Default value of the weight is 1, default mcuadv 10.
+               The scaling factor is therefore 10. */
+            if(weight > 0) mcuadv = 10 / weight;
+            
+            ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv, 
+                                         warpback, warpvalue, warpl, warpu);
+            break;
+        }
+        
+        case SCHED_FBVT:
+        {
+            // TODO
+            break;
+        }
+        case SCHED_RROBIN:
+        {
+            /* The weight cannot be set for RRobin */
+            break;
+        }
+        case SCHED_ATROPOS:
+        {
+            /* TODO - can we set weights in Atropos? */
+            break;
+        }
+    }
+
+    return ret;
+}
+
+
 int xc_domain_setinitialmem(int xc_handle,
                             u32 domid, 
                             unsigned int initial_memkb)
index 62050c83eba91bf87a7141b6934f939b76b66a5c..4f4f2885c6122c5f4c7092725525cf4b60815e51 100644 (file)
@@ -224,7 +224,7 @@ int xc_linux_restore(int xc_handle, XcIOContext *ioctxt)
 
     /* XXX create domain on CPU=-1 so that in future it auto load ballances by default */
     if ( xc_domain_create( xc_handle,  nr_pfns * (PAGE_SIZE / 1024),
-                          name, -1, &dom ) )
+                          name, -1, 1, &dom ) )
     {
        xcio_error(ioctxt, "Could not create domain. pfns=%d, %dKB",
                   nr_pfns,nr_pfns * (PAGE_SIZE / 1024));
index 4b5a426b55ff480f44cc19a81b408758fa6c0b3c..840a954e94a03936f7afcaf221c93bb44b287bde 100644 (file)
@@ -44,16 +44,19 @@ static PyObject *pyxc_domain_create(PyObject *self,
     unsigned int mem_kb = 0;
     char        *name   = "(anon)";
     int          cpu = -1;
+    float        cpu_weight = 1;
     u32          dom = 0;
     int          ret;
 
-    static char *kwd_list[] = { "dom", "mem_kb", "name", "cpu", NULL };
+    static char *kwd_list[] = { "dom", "mem_kb", "name", 
+                                "cpu", "cpu_weight", NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iisi", kwd_list, 
-                                      &dom, &mem_kb, &name, &cpu)
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iisif", kwd_list, 
+                                      &dom, &mem_kb, &name, &cpu, &cpu_weight))
         return NULL;
 
-    if ( (ret = xc_domain_create(xc->xc_handle, mem_kb, name, cpu, &dom)) < 0 )
+    if ( (ret = xc_domain_create(
+                    xc->xc_handle, mem_kb, name, cpu, cpu_weight, &dom)) < 0 )
         return PyErr_SetFromErrno(xc_error);
 
     return PyInt_FromLong(dom);
index 472cc0f74c8fb73e7428a33050b8656f16a59823..2c31d643c1b688a6b4852a003c77be5d61e068be 100644 (file)
@@ -490,6 +490,7 @@ class XendDomainInfo:
         try:
             self.name = sxp.child_value(config, 'name')
             self.check_name(self.name)
+            self.cpu_weight = float(sxp.child_value(config, 'cpu_weight'))
             self.memory = int(sxp.child_value(config, 'memory'))
             if self.memory is None:
                 raise VmError('missing memory size')
@@ -709,8 +710,9 @@ class XendDomainInfo:
         memory = self.memory
         name = self.name
         cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
+        cpu_weight = self.cpu_weight
         dom = self.dom or 0
-        dom = xc.domain_create(dom= dom, mem_kb= memory * 1024, name= name, cpu= cpu)
+        dom = xc.domain_create(dom= dom, mem_kb= memory * 1024, name= name, cpu= cpu, cpu_weight= cpu_weight)
         if dom <= 0:
             raise VmError('Creating domain failed: name=%s memory=%d'
                           % (name, memory))
@@ -1137,12 +1139,13 @@ add_device_handler('vbd',  vm_dev_vbd)
 add_device_handler('pci',  vm_dev_pci)
 
 # Ignore the fields we already handle.
-add_config_handler('name',    vm_field_ignore)
-add_config_handler('memory',  vm_field_ignore)
-add_config_handler('cpu',     vm_field_ignore)
-add_config_handler('console', vm_field_ignore)
-add_config_handler('image',   vm_field_ignore)
-add_config_handler('device',  vm_field_ignore)
-add_config_handler('backend', vm_field_ignore)
+add_config_handler('name',       vm_field_ignore)
+add_config_handler('memory',     vm_field_ignore)
+add_config_handler('cpu',        vm_field_ignore)
+add_config_handler('cpu_weight', vm_field_ignore)
+add_config_handler('console',    vm_field_ignore)
+add_config_handler('image',      vm_field_ignore)
+add_config_handler('device',     vm_field_ignore)
+add_config_handler('backend',    vm_field_ignore)
 
 # Register other config handlers.
index 69d6fb0b1f38390de7bd2b92c25d4541bbceb243..4abbe1b91d54ca67ecfa308e03a885cf491bbddc 100644 (file)
@@ -101,6 +101,10 @@ gopts.var('memory', val='MEMORY',
           fn=set_value, default=128,
           use="Domain memory in MB.")
 
+gopts.var('cpu_weight', val='CPU_WEIGHT',
+          fn=set_value, default=1,
+          use="CPU weight.")
+
 gopts.var('console', val='PORT',
           fn=set_int, default=None,
           use="Console port to use. Default is 9600 + domain id.")
@@ -299,7 +303,8 @@ def make_config(vals):
     
     config = ['vm',
               ['name', vals.name ],
-              ['memory', vals.memory ] ]
+              ['memory', vals.memory ],
+              ['cpu_weight', vals.cpu_weight] ]
     if vals.cpu:
         config.append(['cpu', vals.cpu])
     if vals.blkif:
index e4ee214b543ab40030ca4c7581e804dac8fc51b8..c526f9fc9acc979a90f7b079f9e15efb6eaba2ad 100644 (file)
@@ -143,7 +143,7 @@ static inline u32 calc_avt(struct domain *d, s_time_t now)
     ranfor = (u32)(now - d->lastschd);
     mcus = (ranfor + MCU - 1)/MCU;
 
-    return inf->avt + mcus;
+    return inf->avt + mcus * inf->mcu_advance;
 }